# The Python Standard Modules(Library) and Third Modules(Library)
from sqlalchemy import create_engine,Column
from sqlalchemy import  String,Double,VARCHAR
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.sql import text
from sqlalchemy.ext.declarative import declarative_base
from functools import wraps
# User-defined Modules


# conn_base_str =          "{driver}:        //{username}:{password}@{host_port}/{database}{parameter}"
SQLALCHEMY_DATABASE_URL = f'oracle+cx_oracle://L6K_MYFA:l6k$myfa@10.12.140.4:1521/Myfa'

engine = create_engine(SQLALCHEMY_DATABASE_URL, echo=False, future=True)

SessionFactory = sessionmaker(bind=engine)

def oracle_session(func):
    @wraps(func)
    def wrapper(*args,**kwargs):
        session = scoped_session(SessionFactory) 
        # session = SessionFactory()
        try:
            res = func(session,*args,**kwargs)
            session.commit()
            return res
        except:
            session.rollback()
            raise
        finally:
            session.close()
    return wrapper

    






